野子电竞数据官网改版https://www.xxe.io/全新登场
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
/**
- @API: 24.队员资料
- @Website: https://www.xxe.io/
*/
public class FootballPlayerInfo {
public static void main(String[] args) {
try {
String content = getContent();
JAXBContext jaxbContext = JAXBContext.newInstance(PlayerList.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
PlayerList leagueList = (PlayerList) unmarshaller.unmarshal(new ByteArrayInputStream(content.getBytes()));
leagueList.getPlayerList().forEach(item -> System.out.println(item));
} catch (Throwable t) {
t.printStackTrace();
}
}
/**
* 获取API返回内容
*
* Note: 这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容
*/
private static String getContent() {
try {
StringBuilder builder = new StringBuilder();
List<String> lines = Files.readAllLines(Paths.get("./src/main/resources/FootballPlayerInfo.xml"), StandardCharsets.UTF_8);
lines.forEach(line -> builder.append(line));
return builder.toString();
} catch (Throwable t) {
t.printStackTrace();
return "";
}
}
@XmlRootElement(name = "list")
public static class PlayerList{
@XmlElement(name = "i")
private List<Player> playerList;
public List<Player> getPlayerList() {
return playerList;
}
}
@XmlRootElement
public static class Player{
@XmlElement(name = "id")
private String recordId;
@XmlElement(name = "PlayerID")
private String playerId;
@XmlElement(name = "Name_J")
private String gbName;
@XmlElement(name = "Name_F")
private String bigName;
@XmlElement(name = "Name_E")
private String enName;
@XmlElement(name = "Birthday")
private String birthday;
@XmlElement(name = "Tallness")
private int height;
@XmlElement(name = "Weight")
private int weight;
@XmlElement(name = "Country")
private String country;
@XmlElement(name = "Photo")
private String photo;
@XmlElement(name = "Health")
private String health;
@XmlElement(name = "Value")
private String value;
@XmlElement(name = "Feet")
private String feet;
@XmlElement(name = "Introduce")
private String introduce;
@XmlElement(name = "TeamID")
private String teamId;
@XmlElement(name = "Place")
private String place;
@XmlElement(name = "Number")
private int number;
@XmlElement(name = "EndDateContract")
private String endDateContract;
@Override
public String toString() {
return "Player{" +
"recordId='" + recordId + '\'' +
", playerId='" + playerId + '\'' +
", gbName='" + gbName + '\'' +
", bigName='" + bigName + '\'' +
", enName='" + enName + '\'' +
", birthday='" + birthday + '\'' +
", height=" + height +
", weight=" + weight +
", country='" + country + '\'' +
", photo='" + photo + '\'' +
", health='" + health + '\'' +
", value='" + value + '\'' +
", feet='" + feet + '\'' +
", introduce='" + introduce + '\'' +
", teamId='" + teamId + '\'' +
", place='" + place + '\'' +
", number=" + number +
", endDateContract='" + endDateContract + '\'' +
'}';
}
public String getRecordId() {
return recordId;
}
public String getPlayerId() {
return playerId;
}
public String getGbName() {
return gbName;
}
public String getBigName() {
return bigName;
}
public String getEnName() {
return enName;
}
public String getBirthday() {
return birthday;
}
public int getHeight() {
return height;
}
public int getWeight() {
return weight;
}
public String getCountry() {
return country;
}
public String getPhoto() {
return photo;
}
public String getHealth() {
return health;
}
public String getValue() {
return value;
}
public String getFeet() {
return feet;
}
public String getIntroduce() {
return introduce;
}
public String getTeamId() {
return teamId;
}
public String getPlace() {
return place;
}
public int getNumber() {
return number;
}
public String getEndDateContract() {
return endDateContract;
}
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。